function [KA,Weights,name] = selfCalibprecondition2(TF,w,h,numparams,corrs)
%this function , given a camera center and a focal length and a series of fundamental
%matrices computes the error with respect to a fundamental matrix

[~,numFs]=size(TF);
name='unrobust';
Weights=ones(numFs,1);
%TF=TF*10000;
plotting=0;
numtries=1;
width=w;
height=h;

Knominate=[width 0 width/2; 0 width height/2 ; 0 0 1];
Ke=Knominate/10;

for j=1:numFs
    BF{1,j}=TF{1,j}*(10000/norm(TF{1,j},2));
end



for j=1:numFs

        EM=(Ke')*BF{1,j}*Knominate+(Knominate')*BF{1,j}*Ke+(Ke')*BF{1,j}*Ke;
        thscales=2*(norm(EM,2));
          G=(Knominate')*BF{1,j}*Knominate;
        s=svd(G);
        er=(s(1,1)-s(2,1));
        T2(j,1)=( er)^2;
     
        
end
 



    T2=T2/sum(T2);
    if(sum(sum(isnan(T2)))>0)
        Weights
        T2
        display('error found');
    end
    
    
    
    
    r=T2;
    
    s=0.7413*iqr(r(r>0));
    r=r/(s);
    Weights2=exponfunc(r); % based on median of residuals
    
    
    Weights=Weights2;
    Weights=Weights/sum(Weights); % normalizing
    
    
    
[allsols,  scrs, bestslns] =nonlinearOptimizeselfcalibnormMOD(TF, w,h, numparams ,Weights,numtries);




if(plotting==1)
    plotSelfCalibResults(allsols,  scrs, bestslns,WEIGHTS,numparams);   
end

KA=bestslns;
end
function w = exponfunc(r)
w = (exp(-r));
end
